<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../jquery-3.3.1.min.js"></script>
    <style>
        div {
            position: absolute;
            left: 0;
            width: 100px;
            height: 100px;
            background-color: pink;
        }
    </style>
</head>

<body>
    <div id="dv"></div>
    <!--<script>
        var div = document.querySelector("div");
        var biginx = 0;
        var biginy = 0;
        var x = 0;
        var y = 0;
        div.addEventListener('touchstart', function(e) {
            biginx = e.targetTouches[0].pageX;
            biginy = e.targetTouches[0].pageY;
            x = this.offsetLeft;
            y = this.offsetTop;
        });
        div.addEventListener('touchmove', function(e) {
            var movex = e.targetTouches[0].pageX - biginx;
            var movey = e.targetTouches[0].pageX = biginy;
            $(this).css("top", y + movey + "px");
            $(this).css("left", x + movex + "px");
            e.preventDefault();
        });
    </script>-->
    <script>
        var dv = document.getElementById("dv");
        var x = 0;
        var y = 0;
        var l = 0;
        var t = 0;
        var isD = false;
        dv.onmousedown = function(e) {
            x = e.clientX;
            y = e.clientY;
            l = dv.offsetLeft;
            t = dv.offsetTop;
            isD = true;
            $(dv).css("cursor", "move");
        }
        window.onmousemove = function(e) {
            if (isD == false) {
                return;
            }
            var nx = e.clientX;
            var ny = e.clientY;
            var nl = nx - (x - l);
            var nt = ny - (y - t);
            dv.style.left = nl + 'px';
            dv.style.top = nt + 'px';
        }
        dv.onmouseup = function() {
            isD = false;
            dv.style.cursor = 'default';
        }
    </script>



</body>

</html>